<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="canvas" height="500"></canvas>
    <script>
        var ctx = document.getElementById('canvas').getContext('2d');
        ctx.rect(10, 10, 100, 100);
        ctx.strokeStyle = "red";
        ctx.stroke();

        //开始一个新的路径
        ctx.beginPath();
        ctx.lineWidth = 10;
        ctx.moveTo(120, 120);
        ctx.lineTo(200, 200);
        ctx.strokeStyle = "red";
        ctx.stroke();
    </script>
</body>

</html>